'----------------------------------------------
' Name: Ali Karbassi & Brian Gresl
' Date: January 25, 2007
' Description: Project 1
'              form frmCreate
'----------------------------------------------
Public Class frmCreate

   ''' <summary>
   ''' Sets the max number of buttons that can be on frmShow. Also checks to see if the value is a integer
   ''' between the range of 3 and 5, inclusive.
   ''' </summary>
   ''' <param name="sender"></param>
   ''' <param name="e"></param>
   ''' <remarks></remarks>
   Private Sub cmdSetLimit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles _
   cmdSetLimit.Click

      If Not IsNumeric(Trim(txtLimit.Text)) Or InStr(Trim(txtLimit.Text).ToLower, "e") Then

         MsgBox("Invalid input!", MsgBoxStyle.OkOnly)

      ElseIf Val(Trim(txtLimit.Text)) < 3 Or Val(Trim(txtLimit.Text)) > 5 Then

         MsgBox("Limit must be 3, 4, or 5!", MsgBoxStyle.OkOnly)

      ElseIf Val(Trim(txtLimit.Text)) >= 3 And Val(Trim(txtLimit.Text)) <= 5 Then

         maxButtons = txtLimit.Text

      End If

      txtLimitReset()

   End Sub

   ''' <summary>
   ''' Resets the txtLimit box to the maximum number of buttons allowed (maxButtons).
   ''' </summary>
   ''' <remarks></remarks>
   Private Sub txtLimitReset()

      txtLimit.Text = maxButtons

   End Sub

   ''' <summary>
   ''' Shows the frmShow form.
   ''' </summary>
   ''' <param name="sender"></param>
   ''' <param name="e"></param>
   ''' <remarks></remarks>
   Private Sub btnShow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnShow.Click

      frmShow.Show()

   End Sub

   ''' <summary>
   ''' Exits the application.
   ''' </summary>
   ''' <param name="sender"></param>
   ''' <param name="e"></param>
   ''' <remarks></remarks>
   Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click

      Application.Exit()

   End Sub

   ''' <summary>
   ''' Creates a button after checking for the maximum number of buttons allowed and if the button key is 
   ''' already in the sorted list. Then it calls the frmShowSettings.
   ''' </summary>
   ''' <param name="sender"></param>
   ''' <param name="e"></param>
   ''' <remarks></remarks>
   Private Sub btnCreate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles _
   btnCreate.Click

      If btnList.Count >= maxButtons Then

         MsgBox("There are " & maxButtons & " buttons already!", MsgBoxStyle.OkOnly)

      ElseIf btnList.Contains(txtKey.Text) Then

         MsgBox("A button with this key already exists. Use a different key please.", MsgBoxStyle.OkOnly)

      Else

         Dim NewButton As New Button

         ' Create the new button
         NewButton.Text = Trim(txtCaption.Text)
         NewButton.Size = btnSize
         NewButton.Location = New Point(100, 100)
         AddHandler NewButton.Click, AddressOf frmShow.btnHandler

         ' Put the button on the form
         frmShow.Controls.Add(NewButton)

         ' Put the button in the Sorted List
         btnList.Add(txtKey.Text, NewButton)

         frmShowSettings()

      End If

   End Sub

   ''' <summary>
   ''' Removes button if in the btnList. Else displays an error.
   ''' </summary>
   ''' <param name="sender"></param>
   ''' <param name="e"></param>
   ''' <remarks></remarks>
   Private Sub btnRemove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles _
   btnRemove.Click

      If Not btnList.Contains(txtKey.Text) Then

         MsgBox("No buttons have the key: " & txtKey.Text, MsgBoxStyle.OkOnly)

      Else

         ' Remove the button from the form
         frmShow.Controls.Remove(btnList(txtKey.Text))

         ' Remove the box in the Sorted List
         btnList.Remove(txtKey.Text)

         frmShowSettings()

      End If

   End Sub

   ''' <summary>
   ''' Arranges the buttons and sets the styles of them.
   ''' </summary>
   ''' <remarks></remarks>
   Private Sub frmShowSettings()

      ' Arrange the buttons
      frmShow.ArrangeButtons()

      ' Style the buttons
      frmShow.FontStyleButtons()

   End Sub

End Class
